﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using IconEditor.IconElements;

namespace IconEditor
{
    public partial class Page : UserControl
    {
        private List<BasicShape> ListOfShapes = new List<BasicShape>();

        public Page()
        {
            InitializeComponent();
        }

        private void ShowIcon_Click(object sender, RoutedEventArgs e)
        {
            // po kliknuti by se melo provest rozparsovani obsahu okna InputTextBlock,
            // vytvorit kolekci BasicShapu a zavolat funkci, ktera je zobrazi na Canvas,
            // popripade nahlasit chybu syntaxe a nic nevykreslovat

            // changelog, please update
            // v 0.1, Martin, tato verze ma napevno zadratovane zobrazeni ikony Borata, nic neparsuje

            foreach (BasicShape bs in ListOfShapes)
            {
                TopCanvas.Children.Remove(bs);
            }

            String InputAnnotation = InputTextBlock.Text;
            ListOfShapes = ParseAnnotation(InputAnnotation);

            foreach (BasicShape bs in ListOfShapes)
            {
                TopCanvas.Children.Add(bs);
            }
        }

        private List<BasicShape> ParseAnnotation(string InputAnnotation)
        {
            List<BasicShape> shapes = new List<BasicShape>();

            //Ellipse(visible=true, fillColor={255,127,127}, fillPattern=FillPattern.Solid, extent={{56.05,-19.86},{106.9,0.8964}}),
            shapes.Add(new MoEllipse(
                true,
                Colors.Black,
                Color.FromArgb(255, 255, 127, 127),
                LinePattern.Solid,
                FillPattern.None,
                0.25,
                new double[,] { { 56.05, -19.86 }, { 106.9, 0.8964 } }));

            //Ellipse(visible=true, fillColor={255,127,127}, fillPattern=FillPattern.Solid, extent={{-94.8,-15.43},{-24.89,15.22}}),
            shapes.Add(new MoEllipse(
                true,
                Colors.Black,
                Color.FromArgb(255, 255, 127, 127),
                LinePattern.Solid,
                FillPattern.None,
                0.25,
                new double[,] { { -94.8, -15.43 }, { -24.89, 15.22 } }));

            //Ellipse(visible=true, fillColor={255,127,127}, fillPattern=FillPattern.Solid, extent={{-35.55,-18.83},{64.45,22}}),
            shapes.Add(new MoEllipse(
                true,
                Colors.Black,
                Color.FromArgb(255, 255, 127, 127),
                LinePattern.Solid,
                FillPattern.None,
                0.25,
                new double[,] { { -35.55, -18.83 }, { 64.45, 22 } }));

            //Text(visible=true, lineColor={0,0,255}, fillColor={0,0,255}, fillPattern=FillPattern.Solid, extent={{-99.71,-84.51},{100.2,-44.46}},
            shapes.Add(new MoText(
                true,
                Color.FromArgb(255, 0, 0, 255),
                Color.FromArgb(255, 0, 0, 255),
                LinePattern.Solid,
                FillPattern.Solid,
                0.25,
                new double[,] { { -99.71, -84.51 }, { 100.2, -44.46 } },
                "%name",
                12,
                "GenericFont",
                TextStyle.None));

            return shapes;
        }

        private void GetIcon_Click(object sender, RoutedEventArgs e)
        {
            String res = "";
            foreach (BasicShape bs in ListOfShapes)
            {
                res += bs.GetAnnotation();
            }

            OutputTextBox.Text = res;
        }
    }
}
